package com.lg.desireplayer.db;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import com.lg.desireplayer.bandlist.Band;
import com.lg.desireplayer.bandlist.BandList;

public class LikeUpdater {

	public static int getCurrentCount(int id) {
		Band band = BandList.retrieveBand(id);
		return band.getLikecnt();
	}

	public static void updateLikeCount(int id, boolean count) {
		int currentCount = getCurrentCount(id);

		StringBuffer str1 = new StringBuffer(
				"http://192.168.0.131:8080/com.lg.project.like.cmd.BandLikeUpdateCmd.vcc?id=");
		str1.append(String.valueOf(id));
		str1.append("&like=");
		if(count) {
			currentCount++;		//like
		} else {
			currentCount--;		//unlike
		}
		
		str1.append(String.valueOf(currentCount));

		URL url1 = null;
		try {
			url1 = new URL(str1.toString());
			url1.openStream();
			Band band = BandList.retrieveBand(id);
			band.setLikecnt(currentCount);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void updateLikeMap(int userid, int bandid) {
		StringBuffer str1 = new StringBuffer(
				"http://192.168.0.131:8080/com.lg.project.like.cmd.BandLikeMapUpdateCmd.vcc?userid=");
		str1.append(userid);
		str1.append("&bandid=");
		str1.append(bandid);
		
		URL url1 = null;
		try {
			url1 = new URL(str1.toString());
			url1.openStream();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
